package com.hdsx.restful.glzt.structure.jkss.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.esri.arcgis.geometry.IGeometry;
import com.hdsx.ao.base.BaseOpearte;
import com.hdsx.restful.glzt.roadline.lxxx.bean.Znode;
import com.hdsx.restful.glzt.structure.jkss.bean.Jkss;
import com.hdsx.restful.glzt.structure.jkss.mapper.JkssMapper;
import com.hdsx.restful.glzt.structure.jkss.service.JkssService;
import com.hdsx.restful.glzt.structure.ql.bean.IntValueName;
import com.hdsx.restful.glzt.structure.ql.bean.StatisticalResult;
import com.hdsx.restful.util.Dao;

@Service
public class JkssServiceImpl extends BaseOpearte<Jkss> implements JkssService {

    public JkssServiceImpl() {
        super("GIS_JKSSSB");
    }
    @Resource(name="jkssMapper")
    private JkssMapper mapper;
    @Override
    public List<Dao> getShapeById(String id) {
        Jkss bean = mapper.getShapeById(id);
        IGeometry shape=selectShape("ID='"+id+"'");
        bean.setShape(shape);
        List<Dao> list=new ArrayList<Dao>();
        list.add(new Dao("监控摄像名称",bean.getJkssmc(),bean.getPtx(),bean.getPty()));
        list.add(new Dao("监控摄像编码",bean.getJkssbh()));
        list.add(new Dao("监控摄像类型",bean.getJksblx()));
        list.add(new Dao("行政区划",bean.getXzqhbm()));
        list.add(new Dao("路线名称",bean.getLxmc()));
        list.add(new Dao("路线编码",bean.getLxbm()));
        return list;
    }

    @Override
    public Jkss getOne(String jkssbh) {
        return mapper.queryOne(jkssbh);
    }

	@Override
	public int queryCount(String lxbm,String xzqhbm,String sxxfx,Double qdzh,Double zdzh,String name) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("lxbm", lxbm);
		parameter.put("xzqhbm", xzqhbm);
		parameter.put("sxxfx", sxxfx);
		parameter.put("qdzh", qdzh);
		parameter.put("zdzh", zdzh);
		parameter.put("name", name);
		return mapper.selectCount(parameter);
	}
	@Override
	public List<Jkss> queryList(String lxbm,String xzqhbm,String sxxfx,Double qdzh,Double zdzh,String name,int begin, int end) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("lxbm", lxbm);
		parameter.put("xzqhbm", xzqhbm);
		parameter.put("sxxfx", sxxfx);
		parameter.put("qdzh", qdzh);
		parameter.put("zdzh", zdzh);
		parameter.put("name", name);
		parameter.put("begin", begin);
		parameter.put("end", end);
		List<Jkss> lists=mapper.selectList(parameter);
		return lists;
	}

    @Override
    public int queryJkssCountXzqhbm(String xzqhbm) {
        if(xzqhbm!=null){
            if(xzqhbm.endsWith("0000")){
                xzqhbm=xzqhbm.substring(0,2);
            }else if(xzqhbm.endsWith("00")){
                xzqhbm=xzqhbm.substring(0,4);
            }
        }
        Map<String,Object> parameter=new HashMap<String,Object>();
        parameter.put("xzqhbm", xzqhbm);
        return mapper.countByXzqhbm(parameter);
    }

    @Override
    public List<Jkss> getListByXzqhbm(String xzqhbm, int begin, int end) {
        if(xzqhbm!=null){
            if(xzqhbm.endsWith("0000")){
                xzqhbm=xzqhbm.substring(0,2);
            }else if(xzqhbm.endsWith("00")){
                xzqhbm=xzqhbm.substring(0,4);
            }
        }
        Map<String,Object> parameter=new HashMap<String,Object>();
        parameter.put("xzqhbm", xzqhbm);
        parameter.put("begin", begin);
        parameter.put("end", end);
        return mapper.selectListByXzqhbm(parameter);
    }

    @Override
    public List<Jkss> getListByLxbm(String lxbm, int begin, int end) {
        Map<String,Object> parameter=new HashMap<String,Object>();
        parameter.put("lxbm", lxbm);
        parameter.put("begin", begin);
        parameter.put("end", end);
        List<Jkss> list=mapper.selectListByLxbm(parameter);

        return list;
    }

    @Override
    public int queryJkssCountByLxbm(String lxbm) {
        Map<String,Object> parameter=new HashMap<String,Object>();
        parameter.put("lxbm", lxbm);
        return mapper.countByLxbm(parameter);
    }

    @Override
    public StatisticalResult countByParameter(Map<String,Object> map) {
        List<IntValueName> seriesData = mapper.countTotalByParameter(map);
        List<String> legendData = mapper.selectClassify(map);
        StatisticalResult sr = new StatisticalResult();
        sr.setChartsText("监控摄像设备统计");
        sr.setSeriesData(seriesData);
        sr.setLegendData(legendData);
        return sr;
    }
    @Override
   	public List<Znode> jkssNode() {
   		List<Znode> Node = mapper.node();
   		return Node;
   	}
	 @Override
	 public int countTotal(Map<String, Object> map){
		 return mapper.countTotal(map);
	 }
	 
	 @Override
	 public List<Jkss> listAll(String lxbm,String xzqhbm,String sxxfx,Double qdzh,
			Double zdzh,String name) {
		return mapper.listAll(lxbm,xzqhbm,sxxfx,qdzh,zdzh,name);
	 }
	 @Override
	public Jkss queryById(String id) {
			return mapper.selectById(id);
	}
	/**
	 * 分类细节
	 */
	@Override
	public List<Jkss> detail(Map<String, Object> map){
		return mapper.detail(map);
	}
	@Override
	public int countDetail(Map<String, Object> map) {
		return  mapper.countDetail(map);
	}
	@Override
	public List<String> selectName(String name){
		return mapper.selectName(name);
	}
}
